package ru.myrtle.jst;

import java.text.MessageFormat;

import ru.myrtle.jst.ast.Unit;

/**
 * Represent a compilation problem on a tempalte.
 */
public class Problem {

    /**
     * Enumeration of problem Severities
     */
    public static enum Severity {

        /**
         * The compilation unit has a problem, but it is will not prevent execution.
         */
        WARNING,

        /**
         * The compilation unit has a problem that will prevent execution.
         */
        ERROR
    }

    /*
     *
     */

    private final Unit unit;
    private final Severity severity;
    private final String message;
    private final Object detail;
    private final int line;
    private final int column;

    public Problem(Unit unit, Severity severity, String message, int line, int column) {
        this(unit, severity, message, null, line, column);
    }

    /**
     * Create an new instance.
     *
     * @param severity the problem severity
     * @param message the error message in {@link MessageFormat} style
     * @param detail the detailed information
     * @param line the start line of the problem
     * @param column the column position (one based) of the problem start
     */
    public Problem(Unit unit, Severity severity, String message, Object detail, int line, int column) {
        this.unit = unit;
        this.severity = severity;
        this.message = message;
        this.detail = detail;
        this.line = line;
        this.column = column;
    }

    public Unit getUnit() {
        return unit;
    }

    public Severity getSeverity() {
        return severity;
    }

    public String getMessage() {
        return message;
    }

    public Object getDetail() {
        return detail;
    }

    public int getLine() {
        return line;
    }

    public final int getColumn() {
        return column;
    }
}
